Module Params

    Private ConfigFile As String = "C:\proyectos\WorkSync\moveIt\Config.xml"

    ''' <summary>
    ''' This loads the configuration for the app.
    ''' </summary>
    ''' <param name="args">Arguments from the Command Line</param>
    ''' <remarks>
    ''' 
    ''' They may either start with an / or an - and be separated with an :
    ''' 
    ''' <example>
    ''' 
    ''' Destination
    ''' /D:P (PC) or /D:U (Usb or iPod)
    ''' 
    ''' </example>
    ''' </remarks>
    ''' 
    Friend Sub LoadConfiguration(ByVal args() As String)

        Dim i As Integer
        Dim Parameter As String

        For i = 0 To args.GetUpperBound(0)

            Parameter = args(i).ToLower

            If ((parameter.Length = 4) And _
            ((Left(parameter, 1) = "/") Or (Left(parameter, 1) = "-")) _
            ) Then

                ' Select Parameter
                Select Case Mid(parameter, 2, 1)

                    ' Destination
                    Case "d"
                        SelectDestination(Parameter)
                    Case Else

                        Throw New Exception(BO.Messages.InvalidParameters)

                End Select

            Else
                Throw New Exception(BO.Messages.InvalidParameters)
            End If

        Next

    End Sub

    Private Sub SelectDestination(ByVal Dest As String)

        Select Case Right(Dest, 1)

            Case "p" 'PC

                mdMain.Destination = Destination.PC
                Console.WriteLine("Destination: PC")

            Case "u" 'Portable device

                mdMain.Destination = Destination.USBorPortableDevice
                Console.WriteLine("Destination: USB or Portable Device")

            Case Else
                Throw New Exception(BO.Messages.InvalidParameters)
        End Select

    End Sub

    Friend Function LoadDatabaseProjects() As BO.sSQLServer()

        Dim xmlDoc As New Xml.XmlDocument
        xmlDoc.Load(ConfigFile)

        Dim xmlNL As Xml.XmlNodeList
        xmlNL = xmlDoc.SelectNodes("Projects/SQLServer2005/DB")

        Dim i As Integer
        Dim Dbs(xmlNL.Count - 1) As BO.sSQLServer

        For i = 0 To (xmlNL.Count - 1)

            Dim xmlND As Xml.XmlNode
            xmlND = xmlNL.Item(i)

            Dim SQLServer As BO.sSQLServer
            SQLServer.ServerName = xmlND.Attributes("Server").InnerText
            SQLServer.User = xmlND.Attributes("User").InnerText
            SQLServer.Password = xmlND.Attributes("Pass").InnerText
            SQLServer.Database = xmlND.Attributes("DBName").InnerText

            Dbs(i) = SQLServer

        Next

        Return Dbs

    End Function

    Friend Function LoadOtherProjects() As BO.Project()

        Dim xmlDoc As New Xml.XmlDocument
        xmlDoc.Load(ConfigFile)

        Dim xmlNL As Xml.XmlNodeList
        xmlNL = xmlDoc.SelectNodes("Projects/Other/PJ")

        Dim i As Integer

        Dim Prjs(xmlNL.Count - 1) As BO.Project

        For i = 0 To (xmlNL.Count - 1)

            Dim xmlND As Xml.XmlNode
            xmlND = xmlNL.Item(i)

            Dim Prj As BO.Project
            Prj.ProjectDirectory = xmlND.Attributes("value").InnerText

            Prjs(i) = Prj

        Next

        Return Prjs

    End Function

    Public Enum Destination
        PC = 0
        USBorPortableDevice = 1
    End Enum

End Module
